package com.ddllh.irontomato;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;


public class InventoryActivity extends Activity{
    /** Called when the activity is first created. */
	

	private EditText editText;
	private Button button;
	private ListView listView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        editText=(EditText)findViewById(R.id.editor);
        
        button=(Button)findViewById(R.id.button1);
        button.setText(R.string.btnadd1);
        button.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent=new Intent();
				intent.setClass(InventoryActivity.this, ToDoTodayActivity.class);
				startActivity(intent);
			}
		}) ;
        
        listView=(ListView)findViewById(R.id.List1);
        listView.setAdapter(new ArrayAdapter<String>(this,
        		android.R.layout.simple_list_item_1,
        		new String[]{"Item1","Item2"}));
    }
    
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, 1, 1, R.string.exit);
		menu.add(0, 2, 2, R.string.about);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {	
		if(item.getItemId()==1)
			finish();
		return super.onOptionsItemSelected(item);
	}
    
    public void Add(Task task) {
    	DbHelper.getInstance().insertItem(DbHelper.TABLE_TASK, task);
	}
    
    public void Edit(Task task) {
    	DbHelper.getInstance().UpdateItem(DbHelper.TABLE_TASK, task);
    }
    
    public void Delete(Task task){
    	DbHelper.getInstance().DeleteItem(DbHelper.TABLE_TASK, task);
    }
    
    public void MoveToDoToday(Task task) {
		task.mColumeValue[task.mColumeValue.length - 1] = "1";
		DbHelper.getInstance().UpdateItem(DbHelper.TABLE_TASK, task);
	}
}